import java.util.Arrays;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.05.00
 *Time:00:00
 */
public class MyStack<E> {

    public Object[] elem;
    public int usedSize;

    public MyStack(){
        this.elem = new Object[5];
    }

    public boolean isFull(){
        return usedSize == elem.length;
    }

    public void push(E data){
        if(isFull()){
            elem = Arrays.copyOf(elem,elem.length*2);
        }
        elem[usedSize] = data;
        usedSize++;
    }

    public Object pop(){
        if(isFull()){
            return -1;
        }
        E ret = (E)elem[usedSize - 1];
        usedSize--;
        return ret;
    }

    public Object peek(){
        if(isFull()) return -1;

        return elem[usedSize - 1];

    }

    public boolean isEmpty(){
        return elem.length == 0;
    }

}
